<?php
/**
 * YBaseMessage.php
 *
 * @author Hua Yang <htmlcook@gmail.com>
 * @since 2.0
 */

Yii::import('common.components.mail.YMessageInterface');

/**
 * Class BaseMessage
 */
abstract class YBaseMessage extends CComponent implements YMessageInterface
{

	public function send(YMailerInterface $mailer = null)
	{

		if ($mailer == null && Yii::app()->hasComponent('mail')) {
			$mailer = Yii::app()->mail;
		}

		if ($mailer === null) {
			throw new CException('邮件服务没有配置');
		}

		return $mailer->send($this);
	}

	public function __toString()
	{
		try {
			$this->toString();
		} catch (Exception $e) {
			trigger_error($e->getMessage() . "\n\n" . $e->getTraceAsString());
			return '';
		}
	}
}